package my.poemhelper.mb;

import my.poemhelper.Facade;
import my.poemhelper.vo.Poem;
import my.poemhelper.vo.PoemAnaly;
import my.poemhelper.vo.PoemCheck;


public class PoemMB extends BaseMB<Poem>{
	
	private String queryWord;
	
	private Poem newPoem = new Poem();
	private Poem mPoem = new Poem();
	
	private String addResult;
	private Long optId;
	
	private PoemCheck poemCheck = new PoemCheck();
	private PoemAnaly poemAnaly = new PoemAnaly();
	
	
	public PoemMB(){
		Facade.facade.queryPoemByWord(queryWord, pageControl);
	}
	
	public String doPoemCheck(){
		Facade.facade.doPoemCheck(poemCheck);
		return "poemCheckResult";
	}
	
	public String dopoemAnaly(){
		Facade.facade.doPoemAnaly(poemAnaly);
		return "poemAnalyResult";
	}
	
	public String showPoem(){
		if(optId!=null && optId>0){
			for(Poem p:pageControl.getData()){
				if(p.getId() == optId){
					this.mPoem = p;
				}
			}
			return "poemShow";
		}
		
		return "";
	}
	

	
	public String addPoem(){
		Facade.facade.insertPeom(newPoem);
		newPoem = new Poem();
		addResult = "添加成功";
		Facade.facade.queryPoemByWord(queryWord, pageControl);
		return "addresult";
	}
	public String delPoem(){
		
		if(isLogined()){
			if(optId!=null && optId>0){
				Facade.facade.delPeom(optId);
				Facade.facade.queryPoemByWord(queryWord, pageControl);
			}
			return "";
		}else{
			return "login";
		}
	}
	

	public String queryPoem(){
		Facade.facade.queryPoemByWord(queryWord, pageControl);
		return "";
	}
	public String getQueryWord() {
		return queryWord;
	}
	public void setQueryWord(String queryWord) {
		this.queryWord = queryWord;
	}


	
	public Poem getmPoem() {
		return mPoem;
	}
	public void setmPoem(Poem mPoem) {
		this.mPoem = mPoem;
	}
	public String getAddResult() {
		return addResult;
	}
	public void setAddResult(String addResult) {
		this.addResult = addResult;
	}

	public Poem getNewPoem() {
		return newPoem;
	}

	public void setNewPoem(Poem newPoem) {
		this.newPoem = newPoem;
	}
	public Long getOptId() {
		return optId;
	}
	public void setOptId(Long optId) {
		this.optId = optId;
	}

	
	
	public PoemCheck getPoemCheck() {
		return poemCheck;
	}

	public void setPoemCheck(PoemCheck poemCheck) {
		this.poemCheck = poemCheck;
	}

	public PoemAnaly getPoemAnaly() {
		return poemAnaly;
	}

	public void setPoemAnaly(PoemAnaly poemAnaly) {
		this.poemAnaly = poemAnaly;
	}

	@Override
	protected String getAddString() {
		return "poemAdd";
	}

}
